<template>
  <div class="app-container">
    <el-input v-model="filterText" placeholder="按关键字进行过滤" style="margin-bottom:15px;width:40%;box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)" 
    prefix-icon="el-icon-search" 
    suffix-icon="el-icon-edit"
    autofocus="true"/>

    <el-tree
      ref="tree2"
      :data="data2"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
      icon-class="el-icon-sunny"
      id="subject_tree"
    />

    <!-- <el-table
      :data="tableData"
      :span-method="objectSpanMethod"
      border
      style="width: 100%; margin-top: 20px">
      <el-table-column
        prop="id"
        label="一级分类编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="title"
        label="一级分类名称">
      </el-table-column>
      
    </el-table> -->

  </div>
</template>

<script>
  import subject from '@/api/edu/subject'
  export default {

    data() {
      return {
        filterText: '',
        data2: [],  //返回所有分类数据



        defaultProps: {
          children: 'children',
          label: 'title'
        }
      }
    },
    created() {
        this.getAllSubjectList()
    },
    watch: {
      filterText(val) {
        this.$refs.tree2.filter(val)
      }
    },

    methods: {
      getAllSubjectList() {
          subject.getSubjectList()
              .then(response => {
                  this.data2 = response.data.list
              })
      },
      filterNode(value, data) {
        if (!value) return true
        return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1
      }
    }
  }
</script>
<style scoped>
#subject_tree{
  color:black;
  width:40%;
  font-weight:bold;
  text-indent:5px;
  margin-left:20px;
}
</style>